package javagames.render;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javagames.util.FrameRate;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;


@SuppressWarnings("serial")
public class HelloWorldApp extends JFrame{
	private FrameRate frameRate;
	
	// constructor
	public HelloWorldApp(){
		frameRate = new FrameRate();
	}
	
	// Main function for the gameloop
	protected void CreateAndShowGUI(){
		GamePanel gamePanel = new GamePanel();
		gamePanel.setBackground(Color.BLACK);
		gamePanel.setPreferredSize(new Dimension(320,240));
		getContentPane().add(gamePanel);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("Hello Wordl!");
		pack();
		frameRate.initialize();
		setVisible(true);
	}
	
	private class GamePanel extends JPanel{
		public void paint(Graphics g){
			super.paint(g);
			onPaint(g);
		}
	}
	
	protected void onPaint(Graphics g){
		frameRate.calculate();
		g.setColor(Color.WHITE);
		g.drawString(frameRate.getFrameRate(), 30, 30);
		g.drawString(frameRate.getFrameDelta(), 30, 45);
		repaint();
	}
	
	public static void main(String[] args){
		final HelloWorldApp app = new HelloWorldApp();
		SwingUtilities.invokeLater( new Runnable() { 
			public void run(){
				app.CreateAndShowGUI();
			}
		});
		
	}
}
